package io.renren.task;

import io.renren.modules.generator.service.DeviceAllService;
import io.renren.modules.generator.service.DeviceGasService;
import io.renren.modules.generator.service.DeviceTianruiWaterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author zhangxu
 * @create 2020/8/25
 * Description:
 */
@Component
@EnableScheduling
public class DeviceTask implements CommandLineRunner {
    private static Logger logger = LoggerFactory.getLogger(DeviceTask.class);
    @Autowired
    private DeviceGasService deviceGasService;
    @Autowired
    DeviceTianruiWaterService deviceTianruiWaterService;
    @Autowired
    DeviceAllService deviceAllService;
    @Scheduled(cron = "0 0/4 * * * ? ")
    public void handleDeviceData(){
        logger.info("-----------------DeviceTask start");
        common();
        logger.info("-----------------DeviceTask end");
    }

    public void common(){
        deviceAllService.getRemoteDatas();
        deviceGasService.putData();
        deviceTianruiWaterService.putData();
        deviceAllService.putStatisticsDataForHour();//计算并存储每小时的平均值指标数据
        deviceAllService.putStatisticsForDays();//计算并存储需要按每天平均计算的指标数据
        deviceAllService.putStatisticsForYears();//计算并存储需要按当前年平均计算的指标数据，年直接按天来算
    }

    @Override
    public void run(String... args) throws Exception {
        common();
    }

//    @Scheduled(cron = "0 0 0/1 * * ?  ")
//    @Scheduled(cron = "0 0/1 * * * ? ")
//    public void putData(){
//        deviceAllService.putStatisticsDataForHour();
//    }


}
